﻿<?php 
require '../../frame/base.php';

$goodsid = !empty($_REQUEST['goodsid'])?$_REQUEST['goodsid']:null;
$shopid = !empty($_REQUEST['shopid'])?$_REQUEST['shopid']:null;

// 传入经纬度
$longitude = $_REQUEST['longitude'];
$latitude = $_REQUEST['latitude'];
// 传入经纬度 end
$sql = "SELECT *, (SQRT(POWER(MOD(ABS(longitude - {$longitude}),360),2) + POWER(ABS(latitude - {$latitude}),2))*160) AS distance FROM `shop` where shopid=$shopid  ORDER BY distance";
$distance=$Db->query($sql)[0]['distance'];

$ary = array();
//开始查询
if($shopid && is_numeric($longitude) && is_numeric($latitude)){
	$goodsRes=$Db->table('goods')->where('shopid',$shopid)->select();
	$goodsNum=['goodsNum'=>count($goodsRes)];//计算总商品数
	$shopDetail = $Db->table('shop')->field('name,phone,qq,images,address,licence,content,longitude,latitude')->where('shopid',$shopid)->find();
	$cate = $Db->table('shop')->where('shopid',$shopid)->find()['city'];
	$market = $Db->table('city')->where('id',$cate)->find()['name'];
	$shopAll = $goodsNum+$shopDetail+array('distance'=>$distance)+array('market'=>$market);
	$ary=array('code'=>200,'msg'=>'成功','data'=>$shopAll);

}else{
	$ary=array('code'=>-200,'msg'=>'失败'.$_REQUEST['longitude']."=".$_REQUEST['latitude']."=".$goodsid."=".$shopid);
}

echo json_encode($ary);
